<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "edu_editor".
 *
 * @property int $id
 * @property string $title 名称
 * @property string $context 内容
 * @property int $status 状态-1禁用 1启用
 * @property int $create_time 创建时间
 * @property int $style
 */
class EduEditor extends \yii\db\ActiveRecord
{

    //定义只有两种状态的枚举
    const STATUS_DISABLE = -1; //禁止
    const STATUS_ENABLE = 1; //启用
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'edu_editor';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['context'], 'string'],
            [['status', 'create_time', 'style'], 'integer'],
            [['style'], 'required'],
            [['title'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Title',
            'context' => 'Context',
            'status' => 'Status',
            'create_time' => 'Create Time',
            'style' => 'Style',
        ];
    }

    /**
     * @param $column
     * @param null $value
     * @return bool|mixed
     */
    public static function dropDown($column, $value = null)
    {
        $dropDownList = [
            'isEnable' => [
                '-1' => '禁用',
                '1' => '启用',
            ],
        ];

        if (null !== $value) {
            return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
        } else {
            return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
        }
    }

    /**
     * @return array
     * 获取状态
     */
    public static function allStatus()
    {
        return [self::STATUS_ENABLE=>'启用',self::STATUS_DISABLE=>'禁用'];
    }
}
